/*
 * Authors: Matt Stenzel, Josh Harris, Jon Homan
 * IT 484 Fall 2008
 * */

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Collections;

namespace MahjongTest
{
    public partial class Form1 : Form
    {
        int score = 0;
        Board board = null;
        DateTime startTime = DateTime.Now;

        public Form1()
        {
            InitializeComponent();
        }

        private void quitToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // Display message box to ask user if they really want to quit.
            if (MessageBox.Show("Are you sure you want to quit?", "Quit Application", 
                MessageBoxButtons.YesNo,MessageBoxIcon.Stop) == DialogResult.Yes)
            {
                Application.Exit();
            }
            
        }

        /*
         * This method increments the user's score.
         * */
        public void incrementScore()
        {
            score += 5;
            scoreLabel.Text = score.ToString();
        }

        /*
         * This method decrements the user's score.
         * */
        public void decrementScore()
        {
            score -= 10;
            scoreLabel.Text = score.ToString();
        }

        private void UndoBtn_Click(object sender, EventArgs e)
        {
            board.undoAction();

            // Only have button active when someone has made a match.
            UndoBtn.Enabled = false;
        }

        private void timer1_Tick(object sender, System.EventArgs e)
        {
            TimeSpan timeNow = DateTime.Now.Subtract(startTime);
            label3.Text = timeNow.ToString().Substring(3, 5);
        }

        /*
         * This method stops the timer, gives 100 point bonus, and 
         * displays a label letting the user know they have won.
         * */
        public void winner()
        {
            timer1.Stop();
            score += 100;
            scoreLabel.Text = score.ToString();
            Label winningLabel = new Label();
            winningLabel.Location = new Point(407, 355);
            winningLabel.Text = "YOU WIN!";
            winningLabel.Font = new Font("Microsoft Sans Serif", 26, FontStyle.Bold);
            winningLabel.Size = new Size(186,39);
            backgroundPanel.Controls.Add(winningLabel);
        }

        /*
         * This method starts the game with the Turtle Board.
         * */
        private void chooseTurtleBoard()
        {
            score = 0;
            scoreLabel.Text = score.ToString();
            ArrayList boardLayout = BoardFactory.getBoardLayout("./BoardConfigs/TurtleBoard.txt");
            board = new Board(boardLayout, this);
            board.printBoardLayout();
            backgroundPanel.Controls.Clear();
            board.showBoard(backgroundPanel);
            startTime = DateTime.Now;
            timer1.Start();
            timer1.Tick += new System.EventHandler(this.timer1_Tick);
        }

        /*
         * This method starts the game with the Pyramid Board.
         * */
        private void choosePyramidBoard()
        {
            score = 0;
            scoreLabel.Text = score.ToString();
            ArrayList boardLayout = BoardFactory.getBoardLayout("./BoardConfigs/PyramidBoard.txt");
            board = new Board(boardLayout, this);
            board.printBoardLayout();
            backgroundPanel.Controls.Clear();
            board.showBoard(backgroundPanel);
            startTime = DateTime.Now;
            timer1.Start();
            timer1.Tick += new System.EventHandler(this.timer1_Tick);
        }

        private void pictureBox1_Click(object sender, EventArgs e)
        {
            chooseTurtleBoard();
        }

        private void pictureBox2_Click(object sender, EventArgs e)
        {
            choosePyramidBoard();
        }

        private void turtleBoardToolStripMenuItem_Click(object sender, EventArgs e)
        {
            chooseTurtleBoard();
        }

        private void pyramidBoardToolStripMenuItem_Click(object sender, EventArgs e)
        {
            choosePyramidBoard();
        }
    }
}